﻿scores = {
    'Player 1': 0,
    'Player 2': 0,
    'Player 3': 0
}

function dispCosts()
{
    $('#p1Score').text(scores['Player 1'])
    $('#p2Score').text(scores['Player 2'])
    $('#p3Score').text(scores['Player 3'])
}

$(document).ready(function() {
    /* наша БД */
    var xmlbd = new XmlBd("data/questions.xml", 'data/templates.xslt')
    if (!xmlbd.ok)
    {
        alert('Problem with loading DB.')
        return
    }
    
    var qs = xmlbd.getQuestionSet('game1')
    if (!qs)
    {
        alert('Problem with getting question set.')
        return
    }
    
    /* создаём игровое поле в DOM */
    createPlayField('play-field', qs.themeNames, qs.costs,
        function (theme, cost) {
            var qhtml = qs.getQuestionHtml(theme, cost)
            var question = $(qhtml).appendTo('body')
            question.find('.plus').click(function(){
                var team = $(this).parent().parent().text()
                team = team.slice(0, 8)
                scores[team] += parseInt(cost)
                dispCosts()
                question.remove()
            })
            question.find('.minus').click(function(){
                var team = $(this).parent().parent().text()
                team = team.slice(0, 8)
                scores[team] -= parseInt(cost)
                dispCosts()
                question.remove()
            })
            question.show()
        }
    )
})